#ifndef SERVER_NETWORK_H
#define SERVER_NETWORK_H
#include <QTcpServer>
#include <QTcpSocket>
#include <QObject>
#include <QHash>

class ServerNetwork : public QTcpServer {
    Q_OBJECT
public:
    explicit ServerNetwork(QObject *parent = nullptr);
    ~ServerNetwork();
    // 发送数据到指定套接字（供上层调用）
    void sendDataToClient(QTcpSocket *socket, const QByteArray &data);
    // 获取所有客户端套接字（供上层管理）
    QList<QTcpSocket*> getClients() const;

signals:
    // 原始数据接收信号（传递套接字和数据，不解析内容）
    void rawDataReceived(QTcpSocket *socket, const QByteArray &data);
    void clientDisconnected(QTcpSocket*);

protected:
    void incomingConnection(qintptr socketDescriptor) override;


private:
    QList<QTcpSocket*> clients;
    QMap<QTcpSocket*, QByteArray> bufferMap; // 新增的 bufferMap 声明
};
#endif // SERVER_NETWORK_H
